package leetcode_acm.leetcode_1;

import org.junit.Test;

import java.util.*;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年03月16日 15:44
 */
public class TopKFrequent {
    public int[] topKFrequent(int[] nums, int k) {
        shuffle(nums);

        return null;
    }

    private int part(int[] nums,int l,int r){
        int pivot = nums[l];
        int i = l+1,j = r;
        while(i<=j){
            while (i<r && nums[i] <= pivot){
                i++;
            }
            while (j>l && nums[j] > pivot){
                j--;
            }
            if(i >= j){
                break;
            }
            swap(nums,i,j);
        }
        swap(nums,j,l);
        return j;
    }

    private void shuffle(int[] nums){
        Random random = new Random();
        int n = nums.length;
        for(int i = 0;i<n;i++){
            int r = random.nextInt(n-i);
            swap(nums,i,r);
        }
    }

    private void swap(int[] nums,int i,int j){
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }


}
